package com.eques.bean

/**
 * @description
 * @author Create by yc on 2025/10/29/Wed 11:29
 */
import com.eques.service.DoorBellService
import java.text.SimpleDateFormat
import java.util.*

data class AlarmRecord(
    val fid: String,                    // 文件ID
    val create_time: Long,              // 创建时间戳
    val alarm: Int,                     // 报警类型
    val lock_aid: String,               // 锁辅助ID
    val pid: String,                    // 图片ID
    val time: Long,                     // 时间戳
    val category: Int,                  // 文件类型
    val lock_id: String                 // 设备ID
) {

    /**
     * 获取报警类型描述
     */
    fun getAlarmType(): String {
        return when (alarm) {
            1 -> "错误报警"
            2 -> "胁迫报警"
            3 -> "防撬报警"
            4 -> "钥匙尝试开锁被冻结"
            5 -> "低电量报警"
            6 -> "不能正常出锁舌 6 次"
            7 -> "门铃报警"
            8 -> "门没关好"
            9 -> "锁状态检测错误报警"
            10 -> "开锁异常报警"
            11 -> "关锁异常报警"
            12 -> "指纹尝试开锁被冻结"
            13 -> "卡片尝试开锁被冻结"
            14 -> "系统锁定报警"
            15 -> "遥控尝试开锁被冻结"
            16 -> "密码尝试开锁被冻结"
            17 -> "人脸尝试开锁被冻结"
            18 -> "密码尝试开锁报警"
            19 -> "遥控尝试开锁报警"
            20 -> "卡片尝试开锁报警"
            21 -> "指纹尝试开锁报警"
            22 -> "钥匙尝试开锁报警"
            23 -> "人脸尝试开锁报警"
            24 -> "强行开门"
            25 -> "掌纹尝试开锁报警"
            26 -> "陌生人逗留报警"
            27 -> "门口有陌生人"
            28 -> "门口有人徘徊"
            29 -> "保留"
            30 -> "忘拔钥匙"
            31 -> "锁门提醒"
            32 -> "门已解锁"
            33 -> "任意开锁被冻结"
            34 -> "敲门提醒"
            35 -> "SOS求救提醒"
            36 -> "门已反锁"
            37 -> "常开已开启"
            38 -> "添加用户"
            39 -> "删除用户"
            40 -> "用户初始化"
            41 -> "删除全部用户"
            42 -> "火灾报警"
            43 -> "非活体人脸"
            44 -> "被人尾随"
            45 -> "特斯拉开锁报警"
            46 -> "指静脉尝试开锁被冻结"
            47 -> "指静脉尝试开锁报警"
            48 -> "掌静脉尝试开锁被冻结"
            49 -> "掌静脉尝试开锁报警"
            else -> "未知报警"
        }
    }

    /**
     * 获取文件类型描述
     */
    fun getCategoryType(): String {
        return when (category) {
            0 -> "图片"
            1 -> "视频"
            else -> "未知类型"
        }
    }

    /**
     * 获取格式化时间
     */
    fun getFormattedTime(): String {
        val date = Date(create_time)
        val now = Date()
        val diff = now.time - create_time

        return when {
            diff < 60 * 1000 -> "刚刚"
            diff < 60 * 60 * 1000 -> "${diff / (60 * 1000)}分钟前"
            diff < 24 * 60 * 60 * 1000 -> "${diff / (60 * 60 * 1000)}小时前"
            else -> {
                val sdf = SimpleDateFormat("yyyy年MM月dd日 HH:mm", Locale.getDefault())
                sdf.format(date)
            }
        }
    }

    /**
     * 获取详细时间
     */
    fun getDetailTime(): String {
        val sdf = SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault())
        return sdf.format(Date(create_time))
    }

    /**
     * 生成缩略图URL（根据实际接口调整）
     */
    fun getThumbnailUrl(): String {
        return   DoorBellService.icvss!!.equesGetAlarmfileUrl(pid, "", lock_id).toString();
    }

    /**
     * 是否有图片
     */
    fun hasImage(): Boolean {
        return fid.isNotEmpty()
    }
}

/**
 * 报警列表响应数据
 */
data class AlarmListResponse(
    val reason: String,
    val total: Int,
    val code: Int,
    val offset: Int,
    val max: Int,
    val limit: Int,
    val context: String,
    val list: List<AlarmRecord>
)